<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="select">选择身份</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['system:apply:add']"
              >新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['system:apply:edit']"
              >修改</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['system:apply:remove']"
              >删除</el-button>
            </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="handleCheck"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="aList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="领用单号" align="center" prop="aid" />
      <el-table-column label="领用科室" align="center" prop="kname" />
      <el-table-column label="申请人" align="center" prop="person" />
      <el-table-column label="申请时间" align="center" prop="time" width="180">
<!--        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>-->
      </el-table-column>
      <el-table-column label="流程图" align="center" ><template slot-scope="scope">
        <el-button
          type="text"
          icon="el-icon-view"
          @click="seeView(scope.row)"
        ></el-button>
      </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="success" icon="el-icon-check" @click="agree(scope.row)" circle></el-button>
          <el-button
            type="danger"
            icon="el-icon-close"
            @click="reject(scope.row)"
            circle
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="handleCheck"
    />
    <!--    选择职位    -->
    <el-dialog :title="title" :visible.sync="open" width="200px" append-to-body>
      <el-radio v-model="radio" label="1">科室库主任</el-radio>
      <el-radio v-model="radio" label="2">中心库主任</el-radio>
      <el-radio v-model="radio" label="3">库房管理员</el-radio>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--    流程图显示    -->
      <div class="imgdiv" id="myImage"></div>
  </div>
</template>

<script>
import {listApplydan,findList,agree,reject,build} from "../../../api/system/applydan";
export default {
  name: "check",
  data() {
    return {
      aid: "",
      kcode: null,
      kname: null,
      person: null,
      time: null,
      aid_:null,
      kname_:null,
      person_:null,
      time_: null,
      status: null,
      radio: '1',
      ident:null,
      options: [{
        value: '选项1',
        label: '科室库主任'
      }, {
        value: '选项2',
        label: '中心库主任'
      }, {
        value: '选项3',
        label: '库房管理员'
      }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医院耗材管理系统表格数据
      aList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      isopen:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        aid: "",
        kname: "",
        person: "",
        time:"",
        assignee:"",
      },
      params: {
        processDefinitionId:'',
        processInstanceId:'',
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {

  },
  methods: {
    select(){
      this.handleCheck();
    },
    seeView(row) {
     console.log(row)
      console.log(row.processInstanceId+" "+row.processDefinitionId);
     this.params.processDefinitionId=row.processDefinitionId;
     this.params.processInstanceId=row.processInstanceId;
      build(this.params).then(response=>{
          console.log("response:"+response)
          //document.getElementById("myImage").src='http://127.0.0.1:8080/system/applydan/processDiagram/';
          //var img = new Image();
        //img.src = "data:image/png;base64,"+response;
        //将img容器添加到html的节点中。
        //document.body.appendChild(img);
        document.getElementById("myImage").innerHTML=response;
      })
    },
    // 取消按钮
    cancel() {
    },
    agree(row) {
      console.log("同意"+row.aid);
      agree(row).then(response=>{
          alert("已同意审批");
          this.handleCheck();
      })
    } ,
    reject(row){
      console.log("驳回"+row.aid)
      reject(row).then(response=>{
        alert("已驳回");
        this.handleCheck();
      })
    },
    //审核按钮
    handleCheck() {
      this.reset();
      this.open = true;
      this.title = "请选择您的身份";
    },    // 表单重置
    reset() {
      this.form = {
        id: null,
        kcode: null,
        kname: null,
        hcode: null,
        hname: null,
        num: null,
        person: null,
        ltime: null,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 提交按钮 */
    submitForm() {
      console.log();
      let  assignee='';
      if(this.radio=='1'){
        assignee='科室库主任';
        this.queryParams.assignee=assignee;
      }
      if(this.radio=='2'){
        assignee='中心库主任';
        this.queryParams.assignee=assignee;
      }
      if(this.radio=='3'){
        assignee='库房管理员';
        this.queryParams.assignee=assignee;
      }
      this.open = false;
      this.queryParams.aid=this.aid_;
      this.queryParams.kname=this.kname_;
      this.queryParams.person=this.person_;
      this.queryParams.time=this.time_;
      findList(this.queryParams).then(response=>{
        console.log("*******************"+response.content[0].aid+"*******************");
        this.aList=response.content;
        this.loading=false;

      })
    },
    /** 详情按钮操作 */
    handleDetails(row) {
      console.log(row);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/apply/export', {
        ...this.queryParams
      }, `apply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
#imgdiv{
  margin:0px 400px 0px 400px;
}
</style>
